package com.peak.distribution.entity.agent;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;

import com.peak.distribution.enums.AccountType;
import com.peak.distribution.enums.Constants;
import com.peak.spring.boot.api.entity.DefaultStategyEntity;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Entity
@Table(name = "dis_agent_account")
@Data
@EqualsAndHashCode(callSuper=true)
public class DisAgentAccount extends DefaultStategyEntity {

	private static final long serialVersionUID = Constants.DISTRIBUTION_VERSION;
	
	/** 账户类型 */
	private AccountType type;
	
	/** 开户行 */
	private String bank;
	
	/** 账号 */
	private String accountNo;
	
	/** 总收入 */
	private Integer totalIncome;
	
	/** 总支出 */
	private Integer totalPayout;
	
	/** 签名 */
	private String sign;
	
	/** 代理 */
	private DisAgent agent;

	@ManyToOne
	@JoinColumn(name = "agent_id")
	@Fetch(FetchMode.SELECT)
	@LazyToOne(LazyToOneOption.PROXY)
	public DisAgent getAgent() {
		return agent;
	}

	@Enumerated(EnumType.STRING)
	public AccountType getType() {
		return type;
	}
	
	@Transient
	public String getSignSource() {
		return this.type.getValue() + this.totalIncome + this.totalPayout + this.accountNo;
	}
}
